package org.dromara.system.controller.api;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.system.api.domain.vo.RemoteDictDataVo;
import org.dromara.system.api.domain.vo.RemoteDictTypeVo;
import org.dromara.system.domain.vo.SysDictDataVo;
import org.dromara.system.domain.vo.SysDictTypeVo;
import org.dromara.system.service.ISysDictTypeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: zhou shuai
 * @date: 2024/9/26 20:31
 * @version: v1
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/system/dict")
public class SysDictApiController {

    private final ISysDictTypeService sysDictTypeService;

    /**
     * 根据字典类型查询字典类型
     *
     * @param dictType 字典类型
     * @return 字典类型
     */
    @GetMapping("/type/byType")
    public R<RemoteDictTypeVo> selectDictTypeByType(@RequestParam("dictType") String dictType) {
        SysDictTypeVo vo = sysDictTypeService.selectDictTypeByType(dictType);
        return R.ok(MapstructUtils.convert(vo, RemoteDictTypeVo.class));
    }

    /**
     * 根据字典类型查询字典数据
     *
     * @param dictType 字典类型
     * @return 字典数据集合信息
     */
    @GetMapping("/data/byType")
    public R<List<RemoteDictDataVo>> selectDictDataByType(@RequestParam("dictType") String dictType) {
        List<SysDictDataVo> list = sysDictTypeService.selectDictDataByType(dictType);
        return R.ok(MapstructUtils.convert(list, RemoteDictDataVo.class));
    }

}
